﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using Common;
using LLFM.CAT.Model;

public partial class Admin_Ajax_ImgSeriesUpload : AdminPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string[] filetype = { ".gif", ".png", ".jpg", ".jpeg", ".bmp" };
        try
        {
            HttpPostedFile jpeg_image_upload = Request.Files["Filedata"];
            int imgWidth;
            int imgHeight;
            string subPath = string.Empty;
            string fullPath = Common.FileUploadHelper.BuildSavePath(jpeg_image_upload, System.Configuration.ConfigurationManager.AppSettings["ImagePath"], "SeriesImg", out subPath,"");
            string mapPaht = Server.MapPath("~" + Path.GetDirectoryName(fullPath) + "/");

            Common.Enums.FileUploadResult result = Common.FileUploadHelper.FileUpload(jpeg_image_upload, mapPaht, Path.GetFileName(fullPath), 5242880, filetype, "", out imgWidth, out imgHeight);
            if (result == Common.Enums.FileUploadResult.文件上传成功)
            {
                M_SeriesImages imageM = new M_SeriesImages();
                imageM.Name = Path.GetFileName(fullPath);
                imageM.ImageUrl = ResolveUrl("~" + fullPath.ToLower().Replace("\\", "/").Replace("/websites", ""));
                imageM.CreateTime = DateTime.Now;
                imageM.Id = 0;
                imageM.SeriesId = 0;
                imageM.Sequence = 0;
                imageM.Status = 0;


                string photoJson = JsonHelper.Serialize<M_SeriesImages>(imageM);
                Response.ContentType = "text/plain";
                Response.StatusCode = 200;
                Response.Write(photoJson);

            }
            else
            {
                Response.StatusCode = 500;
                Response.Write("An error occured" + result.ToString());
                Response.End();
            }

        }
        catch
        {
            Response.StatusCode = 500;
            Response.Write("An error occured");
            Response.End();
        }
    }
}
